﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MySql.Data.MySqlClient;
using System.Threading.Tasks;

namespace Woodlands
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
    {
        LoginWindow lWindow;
        StaffWindow staffWindow;
        StudentWindow studentWindow;
        CourseWindow courseWindow;
        ModuleWindow moduleWindow;
        AttendanceWindow attendanceWindow;
        AssignmentWindow assignmentWindow;
        PersonalTutorWindow personalTutorWindow;
        TimetableWindow timetableWindow;
        Staff currentUser;

        public MainWindow()
		{ 
            currentUser = new Staff();
            lWindow = new LoginWindow();
            staffWindow = new StaffWindow();
            studentWindow = new StudentWindow();
            courseWindow = new CourseWindow();
            moduleWindow = new ModuleWindow();
            attendanceWindow = new AttendanceWindow();
            assignmentWindow = new AssignmentWindow();
            personalTutorWindow = new PersonalTutorWindow();
            timetableWindow = new TimetableWindow();
            studentWindow.Content = null;
            staffWindow.Content = null;
            courseWindow.Content = null;
            moduleWindow.Content = null;
            attendanceWindow.Content = null;
            assignmentWindow.Content = null;
            personalTutorWindow.Content = null;
            timetableWindow.Content = null;
			this.InitializeComponent();
            this.ResizeMode = ResizeMode.NoResize;
            this.WindowStyle = WindowStyle.None;
            this.WindowState = WindowState.Maximized;
            lWindow.Content = null;
            mainContent.Children.Add(lWindow.mainContent);
		}

        private void students_Click(object sender, RoutedEventArgs e)
        {
            mainContent.Children.RemoveAt(0);
            mainContent.Children.Add(studentWindow.mainContent);
        }

        public void Login_Successful()
        {
            ChangeButtons(true);
            userLbl.Content = currentUser.FirstName;
            welcomeLbl.Visibility = System.Windows.Visibility.Visible;
            logoutBtn.Visibility = System.Windows.Visibility.Visible;
            systemSearchButton.Visibility = System.Windows.Visibility.Visible;
            systemSearchTxt.Visibility = System.Windows.Visibility.Visible;
            StudentWindow sWindow = new StudentWindow();
            sWindow.Content = null;
            mainContent.Children.RemoveAt(0);
            mainContent.Children.Add(sWindow.mainContent);
        }

        private void ChangeButtons(Boolean x)
        {
            Visibility y;
            if (x)
            {
                y = System.Windows.Visibility.Visible;
                welcomeMessage.Visibility = System.Windows.Visibility.Hidden;
            }
            else
            {
                y = System.Windows.Visibility.Hidden;
                welcomeMessage.Visibility = System.Windows.Visibility.Visible;
            }

            studentsBtn.Visibility = y;
            staffBtn.Visibility = y;
            courseBtn.Visibility = y;
            moduleBtn.Visibility = y;
            assignmentBtn.Visibility = y;
            attendanceBtn.Visibility = y;
            pTutorBtn.Visibility = y;
            timetableBtn.Visibility = y;
        }

        private void logoutBtn_Click(object sender, RoutedEventArgs e)
        {
            mainContent.Children.RemoveAt(0);
            ChangeButtons(false);
            userLbl.Content = "";
            welcomeLbl.Visibility = System.Windows.Visibility.Hidden;
            logoutBtn.Visibility = System.Windows.Visibility.Hidden;
            systemSearchButton.Visibility = System.Windows.Visibility.Hidden;
            systemSearchTxt.Visibility = System.Windows.Visibility.Hidden;
            mainContent.Children.Add(lWindow.mainContent);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            lWindow.setParent(this,currentUser);
            lWindow.UsernameBox.Focus();
        }

        private void staffBtn_Click_1(object sender, RoutedEventArgs e)
        {
            mainContent.Children.RemoveAt(0);
            mainContent.Children.Add(staffWindow.mainContent);
        }

        private void courseBtn_Click_1(object sender, RoutedEventArgs e)
        {
            mainContent.Children.RemoveAt(0);
            mainContent.Children.Add(courseWindow.mainContent);
        }

        private void moduleBtn_Click_1(object sender, RoutedEventArgs e)
        {
            mainContent.Children.RemoveAt(0);
            mainContent.Children.Add(moduleWindow.mainContent);
        }

        private void attendanceBtn_Click_1(object sender, RoutedEventArgs e)
        {
            mainContent.Children.RemoveAt(0);
            mainContent.Children.Add(attendanceWindow.mainContent);
        }

        private void assignmentBtn_Click_1(object sender, RoutedEventArgs e)
        {
            mainContent.Children.RemoveAt(0);
            mainContent.Children.Add(assignmentWindow.mainContent);
        }

        private void personalTutorBtn_Click_1(object sender, RoutedEventArgs e)
        {
            mainContent.Children.RemoveAt(0);
            mainContent.Children.Add(personalTutorWindow.mainContent);
        }

        private void timetableBtn_Click_1(object sender, RoutedEventArgs e)
        {
            mainContent.Children.RemoveAt(0);
            mainContent.Children.Add(timetableWindow.mainContent);
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start("C:\\Windows\\system32\\Magnify.exe");
        }
	}
}